package GameServer

import (
	. "SGNet"
)

func initDispatcher() {
	MessageDispatcher = ServerMessageDispatch
	ClientLostMessage = ClientConnLost
}
func ServerMessageDispatch(Sess *Session, MsgId uint16, Data []byte) {
	if Sess.UserData != nil {
		player := Sess.UserData.(*ClientPlayer)
		if player.PlayerState == PLAYERSTATE_SCENE {
			player.RunScene.AddMessage(&Message{MESSAGETYPE_CLIENT, Sess, MsgId, Data, nil})
			return
		}
	}
	GetModuleByID(MsgId).AddMessage(&Message{MESSAGETYPE_CLIENT, Sess, MsgId, Data, nil})
}

func ClientConnLost(Sess *Session) {
	lostmsg := CmdMessage(CMD_ClientLost, "Sess", Sess)
	if Sess.UserData != nil {
		player := Sess.UserData.(*ClientPlayer)
		if player.PlayerState == PLAYERSTATE_SCENE {
			player.RunScene.AddMessage(lostmsg)
			//return
		}
	}

	for _, md := range moduleMap {
		md.AddMessage(lostmsg)
	}
}
